<?php
require(__DATAGEN_CLASSES__ . '/TableUserProjectGen.class.php');

    /**
     * The TableUserProject class defined here contains any
     * customized code for the TableUserProject class in the
     * Object Relational Model.  It represents the "table_user_project" table
     * in the database, and extends from the code generated abstract TableUserProjectGen
     * class, which contains all the basic CRUD-type functionality as well as
     * basic methods to handle relationships and index-based loading.
     *
     * @package My Application
     * @subpackage DataObjects
     *
     */
class TableUserProject extends TableUserProjectGen {
        /**
         * Default "to string" handler
         * Allows pages to _p()/echo()/print() this object, and to define the default
         * way this object would be outputted.
         *
         * Can also be called directly via $objTableUserProject->__toString().
         *
         * @return string a nicely formatted string representation of this object
         */
    public function __toString() {
        return sprintf('TableUserProject Object %s',  $this->intId);
    }

    public static function bool_exists_by_username($key_)
    {
        $obj=TableUserProject::LoadByUserName($key_);

        if(isset($obj))
        {
            return true;
        }

        return false;
    }

    public static function bool_exists_by_email($key_)
    {
        $obj=TableUserProject::CountByMail($key_);

        if($obj>0)
        {
            return true;
        }

        return false;
    }

    //href
    public function get_href_for_user_page()
    {
        return '/user.php?id='.$this->Id;
    }

    public function get_href_to_invite_popup()
    {
        return '/popup_invite.php?id='.$this->Id;
    }

    public function get_href_to_report_violation_popup()
    {
        return '/popup_report_violation.php?id='.$this->Id;
    }

    //static href
    public static function get_href_my_account()
    {
        return '/my_account.php';
    }
    public static function get_href_my_account_setting()
    {
        return '/my_account_setting.php';
    }
    public static function get_href_my_account_feedbacks()
    {
        return '/my_account_feedbacks.php';
    }

    public static function get_href_my_account_buyer_posting()
    {
        return '/my_account_buyer_posting.php';
    }
    public static function get_href_my_account_buyer_starting()
    {
        return '/my_account_buyer_starting.php';
    }
    public static function get_href_my_account_buyer_closed()
    {
        return '/my_account_buyer_closed.php';
    }
    public static function get_href_my_account_buyer_review()
    {
        return '/my_account_buyer_review.php';
    }

    public static function get_href_my_account_provider_posting()
    {
        return '/my_account_provider_posting.php';
    }
    public static function get_href_my_account_provider_won()
    {
        return '/my_account_provider_won.php';
    }
    public static function get_href_my_account_provider_closed()
    {
        return '/my_account_provider_closed.php';
    }
    public static function get_href_my_account_provider_review()
    {
        return '/my_account_provider_review.php';
    }

    public static function get_href_my_account_manage_payment()
    {
        return '/my_account_manage_payment.php';
    }
    public static function get_href_my_account_transaction_history()
    {
        return '/my_account_transaction_history.php';
    }

    //properties
    public function get_textlink_for_user_page()
    {
        return '<a href="/user.php?id='.$this->Id.'">'.$this->UserName.'</a>';
    }

    public function get_html_rate_as_buyer_avg()
    {
        //<div class="star"><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star_half.jpg" alt="" /><img src="media/black_star_empty.jpg" alt="" /></div><div class="floatRight" style="font-size:12px;">8.5</div>
        return '<div class="star">'.$this->RateAsBuyer.'</div>';
    }

    public function get_html_rate_as_buyer_1()
    {
        //<div class="star"><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star_half.jpg" alt="" /><img src="media/black_star_empty.jpg" alt="" /></div><div class="floatRight" style="font-size:12px;">8.5</div>
        return '<div class="star">'.$this->RateAsBuyer1.'</div>';
    }

    public function get_html_rate_as_buyer_2()
    {
        return '<div class="star">'.$this->RateAsBuyer2.'</div>';
    }

    public function get_html_rate_as_buyer_3()
    {
        return '<div class="star">'.$this->RateAsBuyer3.'</div>';
    }

    public function get_html_rate_as_buyer_4()
    {
        return '<div class="star">'.$this->RateAsBuyer4.'</div>';
    }

    public function get_html_rate_as_buyer_5()
    {
        return '<div class="star">'.$this->RateAsBuyer5.'</div>';
    }

    public function get_html_rate_as_buyer_6()
    {
        return '<div class="star">'.$this->RateAsBuyer6.'</div>';
    }

    public function get_html_rate_as_provider_avg()
    {
        //<div class="star"><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star_half.jpg" alt="" /><img src="media/black_star_empty.jpg" alt="" /></div><div class="floatRight" style="font-size:12px;">8.5</div>
        return '<div class="star">'.$this->RateAsprovider.'</div>';
    }

    public function get_html_rate_as_provider_1()
    {
        //<div class="star"><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star.jpg" alt="" /><img src="media/black_star_half.jpg" alt="" /><img src="media/black_star_empty.jpg" alt="" /></div><div class="floatRight" style="font-size:12px;">8.5</div>
        return '<div class="star">'.$this->RateAsprovider1.'</div>';
    }

    public function get_html_rate_as_provider_2()
    {
        return '<div class="star">'.$this->RateAsprovider2.'</div>';
    }

    public function get_html_rate_as_provider_3()
    {
        return '<div class="star">'.$this->RateAsprovider3.'</div>';
    }

    public function get_html_rate_as_provider_4()
    {
        return '<div class="star">'.$this->RateAsprovider4.'</div>';
    }

    public function get_html_rate_as_provider_5()
    {
        return '<div class="star">'.$this->RateAsprovider5.'</div>';
    }

    public function get_html_rate_as_provider_6()
    {
        return '<div class="star">'.$this->RateAsprovider6.'</div>';
    }

    //functions
    public function set_register_date_for_now()
    {
        $this->RegisterDate=QDateTime::Now();
    }

    public function set_last_access_date_for_now()
    {
        $this->LastAccessDate=QDateTime::Now();
    }

    public function set_login_date_for_now()
    {
        $this->LoginDate=QDateTime::Now();
    }

    public function set_logout_date_for_now()
    {
        $this->LogoutDate=QDateTime::Now();
    }

    public function set_auth_date_for_now()
    {
        $this->AuthorizedDate=QDateTime::Now();
    }


    /*public static function LoadArrayBySearchSiteName($strParam1, $objOptionalClauses) {

        $objDatabase = TableSite::GetDatabase();

        $strParam1 = $objDatabase->SqlVariable($strParam1);
        //$strQuery = "SELECT * FROM `table_site` AS `table_site` WHERE name like `%".$strParam1."%`";

        $strQuery = sprintf('SELECT `table_site`.* FROM `table_site` AS `table_site` WHERE (name) like (%s)',$strParam1);

        //$strQuery = 'SELECT * FROM table_site WHERE name like `a%`';

        $objDbResult = $objDatabase->Query($strQuery);
        return TableSite::InstantiateDbResult($objDbResult);
    }

    public static function LoadCountBySearchSiteName($strParam1, $objOptionalClauses) {

        $objDatabase = TableSite::GetDatabase();

        $strParam1 = $objDatabase->SqlVariable($strParam1);

        //$strQuery = 'SELECT count(*) FROM table_site WHERE name like a%';
        $strQuery = sprintf('SELECT count(*) FROM `table_site` AS `table_site` WHERE (name) like (%s)',$strParam1);

        $objDbResult = $objDatabase->Query($strQuery);
        $objResult=$objDbResult->FetchArray();
        return $objResult[0];
    }

        // Override or Create New Load/Count methods
        // (For obvious reasons, these methods are commented out...
        // but feel free to use these as a starting point)
/*
        public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses = null) {
            // This will return an array of TableUserProject objects
            return TableUserProject::QueryArray(
                QQ::AndCondition(
                    QQ::Equal(QQN::TableUserProject()->Param1, $strParam1),
                    QQ::GreaterThan(QQN::TableUserProject()->Param2, $intParam2)
                ),
                $objOptionalClauses
            );
        }

        public static function LoadBySample($strParam1, $intParam2, $objOptionalClauses = null) {
            // This will return a single TableUserProject object
            return TableUserProject::QuerySingle(
                QQ::AndCondition(
                    QQ::Equal(QQN::TableUserProject()->Param1, $strParam1),
                    QQ::GreaterThan(QQN::TableUserProject()->Param2, $intParam2)
                ),
                $objOptionalClauses
            );
        }

        public static function CountBySample($strParam1, $intParam2, $objOptionalClauses = null) {
            // This will return a count of TableUserProject objects
            return TableUserProject::QueryCount(
                QQ::AndCondition(
                    QQ::Equal(QQN::TableUserProject()->Param1, $strParam1),
                    QQ::Equal(QQN::TableUserProject()->Param2, $intParam2)
                ),
                $objOptionalClauses
            );
        }

        public static function LoadArrayBySample($strParam1, $intParam2, $objOptionalClauses) {
            // Performing the load manually (instead of using QCubed Query)

            // Get the Database Object for this Class
            $objDatabase = TableUserProject::GetDatabase();

            // Properly Escape All Input Parameters using Database->SqlVariable()
            $strParam1 = $objDatabase->SqlVariable($strParam1);
            $intParam2 = $objDatabase->SqlVariable($intParam2);

            // Setup the SQL Query
            $strQuery = sprintf('
                SELECT
                    `table_user_project`.*
                FROM
                    `table_user_project` AS `table_user_project`
                WHERE
                    param_1 = %s AND
                    param_2 < %s',
                $strParam1, $intParam2);

            // Perform the Query and Instantiate the Result
            $objDbResult = $objDatabase->Query($strQuery);
            return TableUserProject::InstantiateDbResult($objDbResult);
        }
*/




    // Override or Create New Properties and Variables
    // For performance reasons, these variables and __set and __get override methods
    // are commented out.  But if you wish to implement or override any
    // of the data generated properties, please feel free to uncomment them.
/*
        protected $strSomeNewProperty;

        public function __get($strName) {
            switch ($strName) {
                case 'SomeNewProperty': return $this->strSomeNewProperty;

                default:
                    try {
                        return parent::__get($strName);
                    } catch (QCallerException $objExc) {
                        $objExc->IncrementOffset();
                        throw $objExc;
                    }
            }
        }

        public function __set($strName, $mixValue) {
            switch ($strName) {
                case 'SomeNewProperty':
                    try {
                        return ($this->strSomeNewProperty = QType::Cast($mixValue, QType::String));
                    } catch (QInvalidCastException $objExc) {
                        $objExc->IncrementOffset();
                        throw $objExc;
                    }

                default:
                    try {
                        return (parent::__set($strName, $mixValue));
                    } catch (QCallerException $objExc) {
                        $objExc->IncrementOffset();
                        throw $objExc;
                    }
            }
        }
*/
}
?>